import {defineStore} from 'pinia'
interface thisstate {
    zhankai:boolean,
    lockscreen:boolean,
    color:string,
    bgimg:string,
    bgtype:string,
    zhezhaoceng:boolean,
}
export const useLayout = defineStore('Layout', {
    state: ():thisstate => {
        return {
            zhankai: false,  // 侧边导航栏的收缩和展开
            lockscreen: false,   // 全局锁屏状态

            color: "#585eaa",  // 背景颜色
            bgimg: "",   // 背景图片
            bgtype: "color",
            zhezhaoceng:false,
        }
    },
    actions: {
        changezhankai(jieguo: boolean | null = null) {
            if (jieguo === null) {
                this.zhankai = !this.zhankai
            } else {
                this.zhankai = jieguo
            }
        },
        changelock(jieguo: boolean | null = null) {
            if (jieguo === null) {
                this.lockscreen = !this.lockscreen;
            } else {
                this.lockscreen = jieguo
            }
        },
        // 更改背景，如果是颜色，就置空图片，如果是图片就置空颜色
        changebg(jieguo: string, type: "color" | "bgimg") {
            console.log(jieguo, "修改背景")
            if (type === "color") {
                this.color = jieguo
                this.bgtype = type
            } else if (type === "bgimg") {
                this.bgimg = jieguo
                this.bgtype = type
            }
        },
        changezhezhao(jieguo: boolean | null = null) {
            if (jieguo === null) {
                this.zhezhaoceng = !this.zhezhaoceng
            } else {
                this.zhezhaoceng = jieguo
            }
        },
    },
    // pinia持久化
    persist: {
        key: 'storekey',    // 加密
        storage: window.sessionStorage, // 存储位置
    },
})
